<!-- 生产负责人 -->
<template>
  <a-spin :spinning="confirmLoading" style="background: #fff">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="8" :hidden="true">
            <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle" >
              <a-input :max-length="255" disabled v-model="model.bpmBizTitle" placeholder="请输入流程名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="单据编号">
              <a-input placeholder="请输入单据编号" v-model="model.billNo" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date
                placeholder="请选择申请时间"
                v-model="model.createTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm"
                style="width: 100%"
                disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createBy">
              <!-- <select-user-by-dep :multi="false" v-model="model.handlerId" disabled /> -->
              <j-select-user-by-dep v-model="model.createBy" :multi="false" disabled></j-select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sysOrgCode">
              <!-- <j-select-depart v-model="model.handlerDeptId" disabled/> -->
              <j-select-depart v-model="model.sysOrgCode" :trigger-change="true" disabled customReturnField="orgCode" :multi="true"></j-select-depart>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-collapse v-model="activeKey">
          <a-collapse-panel key="1" header="项目信息">
            <a-row :gutter="48">
              <a-col :span="8">
                <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
                  <select-project-input disabled v-model="model.projectId" placeholder="请选择项目名称" @input="onChangeProjectName"></select-project-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="finalNo">
                  <a-input disabled v-model="model.finalNo" placeholder="请输入项目编号"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamName">
                  <select-team-input
                    disabled
                    v-model="model.teamName"
                    :tdlx="1"/>

                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="undertaker">
                  <select-user-by-dep disabled :multi="false" v-model="model.undertaker" /></a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="立项日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectEstablishDate">
                  <j-date
                    disabled
                    placeholder="请选择立项日期"
                    v-model="model.projectEstablishDate"
                    :show-time="true"
                    date-format="YYYY-MM-DD HH:mm"
                    style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="签订单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signUnit">
                  <select-Company-input placeholder="请选择签订单位" disabled v-model="model.signUnit"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
                  <j-dict-select-tag
                    disabled
                    type="list"
                    v-model="model.year"
                    dictCode="yjgsnd"
                    placeholder="请选择业绩归属年度"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="业主单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerUnit">
                  <select-customer-input
                    disabled
                    v-model="model.ownerUnit"
                    commercialType="1"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contacts">
                  <j-dict-select-tag
                    disabled
                    type="list"
                    v-model="model.contacts"
                    :dictCode="cust_lxr"
                    placeholder="请选择联系人"
                  />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactTel">
                  <a-input disabled v-model="model.contactTel" placeholder="请输入联系电话"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8" >
                <a-form-model-item prop="areaCode" label="项目所在地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <AddressChoice disabled type="cascader" v-model="model.areaCode" placeholder="请输入省市区" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item prop="projectAddress" label="项目详细地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input disabled v-model="model.projectAddress" placeholder="请输入项目详细地址"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="项目来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectSource">
                  <j-dict-select-tag
                    disabled
                    type="list"
                    v-model="model.projectSource"
                    dictCode="xmly_type"
                    placeholder="请选择项目来源"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="预计合同额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="estimatedContractAmount">
                  <a-input-number
                    disabled
                    :max="99999999"
                    :min="0"
                    :precision="2"
                    v-model="model.estimatedContractAmount"
                    placeholder="请输入预计合同额"
                    style="width: 100%"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="预计合同额大写" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="estimatedContractcapitalChineseAmount">
                  <a-input disabled v-model="model.estimatedContractcapitalChineseAmount" placeholder="请输入预计合同额大写"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="立项事由及说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="establishReason">
                  <a-textarea :max-length="500" disabled v-model="model.establishReason" rows="4" placeholder="请输入立项事由及说明"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="项目附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachment">
                  <j-upload v-if="!formDisabled" disabled v-model="model.attachment"></j-upload>
                  <a-button v-else icon="download" @click="viewFile(model.attachment)">文件列表</a-button>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-collapse-panel>
          <a-collapse-panel key="2" header="任务信息">
            <a-row :gutter="48">
              <a-col :span="8">
                <!-- @back="changeTask" -->
                <a-form-model-item label="任务编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskId">
                  <SelectTaskFileInput
                    disabled
                    v-model="model.taskId"
                    @input="onTaskIdInput"
                  />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="业务分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categoryName">
                  <a-input
                    disabled
                    v-model="model.categoryName"
                    placeholder="请选择业务分类" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="合同占比(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractRate">
                  <a-input-number
                    disabled
                    :max="99999999"
                    :min="0"
                    :precision="2"
                    v-model="model.contractRate"
                    placeholder="请输入合同占比"
                    style="width: 100%"
                  />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="合同分配额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractAmount">
                  <a-input-number
                    disabled
                    :max="99999999"
                    :min="0"
                    :precision="2"
                    v-model="model.contractAmount"
                    placeholder="请输入合同分配额"
                    style="width: 100%"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="切割合同额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractAmount">
                  <a-input-number
                    disabled
                    :max="99999999"
                    :min="0"
                    :precision="2"
                    v-model="model.cutContractAmount"
                    placeholder="请输入切割合同额"
                    style="width: 100%"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="生产团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productTeam">
                  <select-team-input
                    disabled
                    v-model="model.productTeam"
                    :tdlx="2"
                    :triggerChange="true"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="任务类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskType">
                  <j-dict-select-tag
                    :disabled="formDisabled"
                    type="list"
                    v-model="model.taskType"
                    dictCode="task_type"
                    placeholder="请选择任务类型"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="实施部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="executeDepart">
                  <j-select-depart :disabled="formDisabled" v-model="model.executeDepart" @input="onExecuteDepartInput"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item
                  label="部门负责人"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  prop="minister">
                  <select-user-by-dep v-model="model.minister" multi :disabled="formDisabled"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item
                  label="项目负责人"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  prop="projectLeading">
                  <select-user-by-dep v-model="model.projectLeading" :disabled="formDisabled"/>
                </a-form-model-item>
              </a-col>

              <!-- 当任务类型为环评咨询，水保咨询时，展示本项 -->
              <template v-if="model.taskType == 1 || model.taskType == 4">
                <a-col :span="8" v-if="model.taskType == 1">
                  <a-form-model-item
                    label="审核工程师"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    prop="approvalEngineer">
                    <select-user-by-dep v-model="model.approvalEngineer" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item
                    label="审批级别"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    prop="approvalLevel">
                    <j-dict-select-tag
                      :disabled="formDisabled"
                      type="list"
                      v-model="model.approvalLevel"
                      dictCode="approval_level"
                      placeholder="请选择审批级别"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="审批系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvalCoefficient">
                    <a-input-number
                      :precision="1"
                      :disabled="formDisabled"
                      v-model="model.approvalCoefficient"
                      placeholder="请输入审批系数"
                      :min="0"
                      :max="99999"
                      style="width: 100%;"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="行业类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryCategory">
                    <j-dict-select-tag
                      :disabled="formDisabled"
                      type="list"
                      v-model="model.industryCategory"
                      dictCode="	industry_category"
                      placeholder="请选择行业类别"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="行业系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryCoefficient">
                    <a-input-number
                      :precision="1"
                      :disabled="formDisabled"
                      v-model="model.industryCoefficient"
                      placeholder="请输入行业系数"
                      :min="0"
                      :max="99999"
                      style="width: 100%;"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="复杂程度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="complexity">
                    <j-dict-select-tag
                      :disabled="formDisabled"
                      type="list"
                      v-model="model.complexity"
                      dictCode="industry_coefficient"
                      placeholder="请选择复杂程度"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="复杂系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="complexCoefficient">
                    <a-input-number
                      :precision="1"
                      :disabled="formDisabled"
                      v-model="model.complexCoefficient"
                      placeholder="请输入复杂系数"
                      :min="0"
                      :max="99999"
                      style="width: 100%;"/>
                  </a-form-model-item>
                </a-col>
              </template>

              <!-- 当任务类型为检验检测时，展示本项 -->
              <template v-if="model.taskType == 2">
                <a-col :span="8">
                  <a-form-model-item label="是否出具报告" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isOutReport">
                    <!-- @input="isTeamworkChange" -->
                    <j-dict-select-tag
                      disabled
                      type="radio"
                      v-model="model.isOutReport"
                      dictCode="YES_OR_NO"
                      placeholder="请选择是否出具报告"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="费用核算方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="expenseAccountingMethod">
                    <j-dict-select-tag
                      :disabled="formDisabled"
                      type="list"
                      v-model="model.expenseAccountingMethod"
                      dictCode="expense_accounting_method"
                      placeholder="请选择费用核算方式"/>
                  </a-form-model-item>
                </a-col>
              </template>
              <a-col :span="24">
                <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instruction">
                  <a-textarea :max-length="500" :disabled="formDisabled" v-model="model.instruction" rows="4" placeholder="请输入说明"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="任务附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskFile">
                  <j-upload v-if="!formDisabled" :disabled="formDisabled" v-model="model.taskFile"></j-upload>
                  <a-button v-else icon="download" @click="viewFile(model.taskFile)">文件列表</a-button>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel key="3" header="项目成员">
            <a-row :gutter="48">
              <a-col :span="24" >
                <!-- <div style="margin-bottom: 6px;margin-top: 6px" >
                <a-button @click="handleMemberAdd" v-if="!formDisabled" type="primary">新增</a-button>
              </div> -->
                <a-table
                  ref="table"
                  size="middle"
                  rowKey="id"
                  :loading="memberLoading"
                  :columns="memberColumns"
                  :pagination="false"
                  :data-source="model.distributionDtList"
                  bordered
                  :components="draggableComponent"
                  :scroll="{x: scrollX}"
                >
                  <span slot="action" slot-scope="text, record">
                    <template v-if="!formDisabled">
                      <a-button
                        class="ruleButton"
                        :ghost="true"
                        type="primary"
                        icon="edit"
                        @click="handleMemberEdit(record)"/>
                      <a-divider type="vertical"/>
                      <a-popconfirm title="确定删除吗?" @confirm="() => handleMemberDelete(record.id)">
                        <a-button
                          class="ruleButton"
                          :ghost="true"
                          type="primary"
                          icon="delete"
                        />
                      </a-popconfirm>
                    </template>
                  </span>
                </a-table>
              </a-col>
            </a-row>
          </a-collapse-panel>
          <a-collapse-panel key="4" header="项目预算">
            <a-row :gutter="48">
              <a-col :span="8">
                <a-form-model-item label="预算总工时(人小时)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="expectWorkTime">
                  <a-input-number
                    disabled
                    :max="9999999"
                    :min="0"
                    :precision="1"
                    v-model="model.expectWorkTime"
                    placeholder="请输入预算总工时"
                    style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="生产总绩效(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalProductPerformance">
                  <a-input-number
                    disabled
                    :max="9999999"
                    :min="0"
                    :precision="2"
                    v-model="model.totalProductPerformance"
                    placeholder="请输入生产总绩效"
                    style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="人工总成本(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workCost">
                  <a-input-number
                    disabled
                    :max="9999999"
                    :min="0"
                    :precision="2"
                    v-model="model.workCost"
                    placeholder="请输入人工总成本"
                    style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="委外费(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outsourcingFee">
                  <a-input-number
                    disabled
                    :max="99999999"
                    :min="0"
                    :precision="2"
                    v-model="model.outsourcingFee"
                    placeholder="请输入委外费"
                    style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="差旅费(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="travelFee">
                  <a-input-number
                    disabled
                    :max="99999999"
                    :min="0"
                    :precision="2"
                    v-model="model.travelFee"
                    placeholder="请输入差旅费"
                    style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="专家评审费(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="professionReviewFee">
                  <a-input-number
                    disabled
                    :max="99999999"
                    :min="0"
                    :precision="2"
                    v-model="model.professionReviewFee"
                    placeholder="请输入专家评审费"
                    style="width: 100%" />
                </a-form-model-item>
              </a-col>

              <a-col :span="8" >
                <a-form-model-item label="其他成本(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="otherCost">
                  <a-input-number
                    disabled
                    :max="99999999"
                    v-model="model.otherCost"
                    :precision="2"
                    placeholder="请输入其他成本"
                    style="width: 100%"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="项目预算合计(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalProjectBudget">
                  <a-input-number
                    disabled
                    :max="99999999"
                    v-model="model.totalProjectBudget"
                    :precision="2"
                    placeholder="请输入项目预算合计"
                    style="width: 100%"/>
                </a-form-model-item>
              </a-col>
              <template v-if="model.categoryName">
                <a-col :span="8" v-if="isProjectInformation">
                  <a-form-model-item label="项目预算表" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectBudgetFile">
                    <a-button icon="download" @click="viewFile(model.projectBudgetFile)">文件列表</a-button>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" v-else>
                  <a-form-model-item label="生产绩效表" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productBudgetFile">
                    <a-button icon="download" @click="viewFile(model.productBudgetFile)">文件列表</a-button>
                  </a-form-model-item>
                </a-col>
              </template>
            </a-row>
          </a-collapse-panel>
          <a-collapse-panel key="5" header="任务进度">
            <a-row :gutter="48">
              <a-col :span="8">
                <a-form-model-item label="进度模板" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateId">
                  <select-process-template-input v-model="model.templateId" disabled placeholder="请选择进度模板" :multi="false" @input="getTemplateList" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="允许添加子节点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isAddChildNode">
                  <j-dict-select-tag
                    type="list"
                    v-model="model.isAddChildNode"
                    disabled
                    dictCode="yes_no"
                    placeholder="请选择允许添加子节点"
                  />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="收入确认方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="confirmIncomeMethod">
                  <j-dict-select-tag disabled type="list" v-model="model.confirmIncomeMethod" dictCode="confirm_income_method" placeholder="请选择收入确认方式" />
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <!-- :loading="memberLoading" -->
                <a-table
                  ref="table"
                  size="middle"
                  rowKey="id"
                  :pagination="false"
                  :columns="templateColumns"
                  :loading="templateLoading"
                  :data-source="templateDataList"
                  :scroll="{x: true}"
                >
                  <template slot="titleSlot" slot-scope="text">
                    <span v-if="text">
                      {{ text }}%
                    </span>
                    <span v-if="!text">
                      -
                    </span>
                  </template>
                </a-table>
              </a-col>
            </a-row>
          </a-collapse-panel>
          <a-collapse-panel key="6" header="款项进度">
            <a-row :gutter="48">
              <a-col :span="24">
                <a-table
                  ref="table"
                  size="middle"
                  rowKey="id"
                  :columns="paymentProgressColumns"
                  :loading="progressNodeVoLoading"
                  :pagination="false"
                  :data-source="progressNodeVoList"
                  bordered
                  :components="draggableComponentOther"
                  :scroll="{x:scrollXOther}"
                  :locale="tableNoData"
                >
                  <span slot="action" slot-scope="text, record">
                    <a-button
                      type="link"
                      @click="handlerPaymentEdit(record)"
                    >完善</a-button>
                  </span>
                </a-table>
              </a-col>
              <!-- <a-col :span="8">
                <a-form-model-item label="履约保证金(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bail">
                  <a-input-number
                    :precision="2"
                    v-model="model.bail"
                    placeholder="请输入履约保证金"
                    disabled
                    :min="0"
                    :max="999999999"
                    style="width: 100%"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="应收日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="collectionDate">
                  <j-date
                    disabled
                    placeholder="请选择应收日期"
                    v-model="model.collectionDate"
                    date-format="YYYY-MM-DD"
                    style="width: 100%"
                  />
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="款项节点说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentDesc">
                  <a-textarea :max-length="200" disabled v-model="model.paymentDesc" rows="4" placeholder="请输入款项节点说明"/>
                </a-form-model-item>
              </a-col> -->
            </a-row>
          </a-collapse-panel>
        </a-collapse>
      </a-form-model>
      <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData" style="margin-top: 10px"></common-flow-list>
      <view-file-modal ref="viewFileModal"></view-file-modal>
      <!-- <erp-omc-prepare-project-item-modal ref="itemList" @ok="modalFormOk"></erp-omc-prepare-project-item-modal> -->
    </j-form-container>
    <a-row :gutter="48">
      <a-col :span="24" style="text-align: center;margin-top: 15px">
        <a-button type="primary" v-if="formBpm" :style="{ marginRight: showFlowSubmitButton?'10px':'0px' }" @click="onPrint">打印</a-button>
        <a-button @click="submitForm('submit')" v-if="showFlowSubmitButton">提 交</a-button>
      </a-col>
    </a-row>

    <ErpOmcTaskDistributionFormPrint class="print_style" v-if="formBpm" id="taskContent" :formData="model1" :formDataHistory="formData"></ErpOmcTaskDistributionFormPrint>
  </a-spin>
</template>

<script>

import { getAction, httpAction } from '@/api/manage'
import { viewFile } from '@/utils/util'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import ViewFileModal from '@/views/scy/components/ViewFileModal'
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
import AddressChoice from '@/components/AddressChoice/AddressChoice';
import { mapGetters } from 'vuex';
import moment from 'moment';
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import CommonFlowList from '@/views/components/CommonFlowList.vue';
import Print from '@/utils/print/printarea.js';
import ErpOmcTaskDistributionFormPrint from './ErpOmcTaskDistributionFormPrint' // 打印
import SelectProjectInput from '@/views/scy/components/SelectProjectInput'; //  项目名称
import SelectTaskFileInput from '@/views/scy/components/SelectTaskFileInput'; //  任务编号
import SelectProcessTemplateInput from '@/views/scy/components/SelectProcessTemplateInput' // 进度模板
import { DragResizable } from '@/mixins/DragResizable'

export default {
  name: 'ErpOmcTaskDistributionFormProductionManBack',
  mixins: [DisabledAuthFilterMixin, viewFile, DragResizable],
  components: {
    ViewFileModal,
    SelectUserByDep,
    SelectTeamInput,
    SelectCustomerInput,
    AddressChoice,
    SelectCompanyInput,
    CommonFlowList,
    ErpOmcTaskDistributionFormPrint,
    SelectProjectInput, //  项目名称
    SelectTaskFileInput, // 任务编号
    SelectProcessTemplateInput
  },
  props: {
    // 流程表单data
    formData: {
      type: Object,
      default: () => {
      },
      required: false
    },
    // 表单模式：true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      activeKey: ['1', '2', '3', '4', '5', '6'],
      tableNoData: { emptyText: () => (
        <a-empty description="合同未签订，暂无数据" />
      ) },
      templateDataList: [], // 进度模板列表
      progressNodeVoList: [], // 款项进度列表
      templateLoading: false,
      progressNodeVoLoading: false,

      memberLoading: false,
      memberColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '项目成员',
          align: 'center',
          dataIndex: 'projectMember_dictText',
          width:100,
          ellipsis: true,
        },
        {
          title: '分配合同额(元)',
          align: 'center',
          dataIndex: 'contractAmount',
          width:140,
          ellipsis: true,
        },
        {
          title: '合同额占比(%)',
          align: 'center',
          dataIndex: 'contractRate',
          width:135,
          ellipsis: true,
        },
        {
          title: '工时单价(元)',
          align: 'center',
          dataIndex: 'dayCost',
          width:120,
          ellipsis: true,
        },
        {
          title: '预算工时(小时)',
          align: 'center',
          dataIndex: 'expectWorkTime',
          width:120,
          ellipsis: true,
        },
        {
          title: '项目绩效(元)',
          align: 'center',
          dataIndex: 'projectPerformance',
          width:120,
          ellipsis: true,
        },
        {
          title: '人工成本(元)',
          align: 'center',
          dataIndex: 'laborCost',
          width:120,
          ellipsis: true,
        }
      ],
      // 进度列表
      templateColumns: [
        {
          title: '顺序',
          dataIndex: '',
          key: 'rowIndex',
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '节点名称',
          align: 'center',
          dataIndex: 'nodeName'
        },
        {
          title: '节点进度',
          align: 'center',
          dataIndex: 'nodeProgress',
          scopedSlots: { customRender: 'titleSlot' }
        },
        {
          title: '收入确认节点',
          align: 'center',
          dataIndex: 'isConfirmIncomeNode_dictText'
        }
      ],

      // 款项进度
      paymentProgressColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '款项名称',
          align: 'center',
          ellipsis: true,
          width: 144,
          dataIndex: 'nodeName'
        },
        {
          title: '金额(元)',
          align: 'center',
          ellipsis: true,
          width: 144,
          dataIndex: 'paymentMoney'
        },
        {
          title: '款项节点说明',
          align: 'center',
          ellipsis: true,
          width: 144,
          dataIndex: 'nodeDesc'
        },
        // {
        //   title: '应收日期',
        //   align: 'center',
        //   ellipsis: true,
        //   dataIndex: 'collectionDate'
        // },
        // {
        //   title: '是否关联任务',
        //   align: 'center',
        //   ellipsis: true,
        //   width: 144,
        //   customRender: (text) => {
        //     if (text === '' || text === null || text === undefined) {
        //       return ''
        //     } else {
        //       return text == 0 ? '否' : '是'
        //     }
        //   },
        //   dataIndex: 'isRelatedTask'
        // },
        // {
        //   title: '是否关联进度',
        //   align: 'center',
        //   ellipsis: true,
        //   width: 144,
        //   customRender: (text) => {
        //     if (text === '' || text === null || text === undefined) {
        //       return ''
        //     } else {
        //       return text == 0 ? '否' : '是'
        //     }
        //   },
        //   dataIndex: 'isRelatedTaskNode'
        // },
        {
          title: '本任务关联款项金额(元)',
          align: 'center',
          ellipsis: true,
          width: 144,
          dataIndex: 'taskPaymentMoney'
        },
        {
          title: '任务进度',
          align: 'center',
          ellipsis: true,
          width: 144,
          dataIndex: 'taskNodeId_dictText'
        },
        {
          title: '节点进度(%)',
          align: 'center',
          ellipsis: true,
          width: 144,
          dataIndex: 'taskProgress'
        }
      ],

      model: {
        distributionDtList: []
      },
      model1: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      confirmLoading: false,
      validatorRules: {
        projectId: [
          { required: true, message: '请选择项目名称!' }
        ],
        taskId: [
          { required: true, message: '请选择任务编号!' }
        ],
        taskType: [
          { required: true, message: '请选择任务类型!' }
        ],
        executeDepart: [
          { required: true, message: '请选择实施部门!' }
        ],
        minister: [
          { required: true, message: '请选择部门负责人!' }
        ]
        // projectLeading: [
        //   { required: true, message: '请选择项目负责人!' }
        // ]
      },
      url: {
        add: '/api/erp/omc/task/erpOmcTaskDistribution/add',
        edit: '/api/erp/omc/task/erpOmcTaskDistribution/edit',
        queryById: '/api/erp/omc/task/erpOmcTaskDistribution/queryById',
        erpOmcProjectQueryById: '/api/erp/omc/project/erpOmcProject/queryById',
        queryPageList: '/api/erp/omc/project/erpOmcProjectTaskFinal/queryPageList',
        generatedFormNumber: '/api/erp/base/generatedFormNumber'
      },
      dictOptions: {},
      cust_lxr: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=0'
    }
  },

  watch: {
    // 监听任务类型
    'model.taskType': {
      handler (val) {
        if (val && (val == 1 || val == 4)) {
          this.$set(this.validatorRules, 'approvalLevel', [{ required: true, message: '请选择审批级别!' }]);
          this.$set(this.validatorRules, 'approvalCoefficient', [{ required: true, message: '请输入审批系数!' }]);
          this.$set(this.validatorRules, 'industryCategory', [{ required: true, message: '请选择行业类别!' }]);
          this.$set(this.validatorRules, 'industryCoefficient', [{ required: true, message: '请输入行业系数!' }]);
          this.$set(this.validatorRules, 'complexity', [{ required: true, message: '请选择复杂程度!' }]);
          this.$set(this.validatorRules, 'complexCoefficient', [{ required: true, message: '请选择复杂系数!' }]);
          this.$delete(this.validatorRules, 'expenseAccountingMethod');
        } else if (val && val == 2) {
          this.$set(this.validatorRules, 'expenseAccountingMethod', [{ required: true, message: '请选择复用核算方式!' }]);
          this.$delete(this.validatorRules, 'approvalLevel');
          this.$delete(this.validatorRules, 'approvalCoefficient');
          this.$delete(this.validatorRules, 'industryCategory');
          this.$delete(this.validatorRules, 'industryCoefficient');
          this.$delete(this.validatorRules, 'complexity');
          this.$delete(this.validatorRules, 'complexCoefficient');
        } else {
          this.$delete(this.validatorRules, 'approvalLevel');
          this.$delete(this.validatorRules, 'approvalCoefficient');
          this.$delete(this.validatorRules, 'industryCategory');
          this.$delete(this.validatorRules, 'industryCoefficient');
          this.$delete(this.validatorRules, 'complexity');
          this.$delete(this.validatorRules, 'complexCoefficient');
          this.$delete(this.validatorRules, 'expenseAccountingMethod');
        }
      },
      immediate: true
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    },
    // 判断是否为工程运维或者数字信息的业务分类
    isProjectInformation() {
      // 判断categoryName是否含有工程运维或者数字信息
      if (this.model.categoryName && (this.model.categoryName.indexOf('工程运维') !== -1 || this.model.categoryName.indexOf('数字信息') !== -1)) {
        return true
      } else {
        return false
      }
    }
  },
  created() {
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    // 如果是流程中表单，则需要加载流程表单data
    this.showFlowData();
    this.customKey = 'memberColumns'
    this.otherKey = 'paymentProgressColumns'
    this.memberColumnswidth = this.memberColumns.map(val => {
      return val.width
    })
    this.paymentProgressColumnswidth = this.paymentProgressColumns.map(val => {
      return val.width
    })
  },
  methods: {
    ...mapGetters(['userInfo']),

    // 获取单据编号
    generatedFormNumber() {
      getAction(this.url.generatedFormNumber, { prefix: 'RWFP', subSystemCode: '05' }).then(res => {
        if (res.success) {
          this.$set(this.model, 'billNo', res.result)
        }
      })
    },

    // 选择项目名称
    onChangeProjectName (item) {
      var event = item.choseObj[0]
      this.$set(this.model, 'projectName', event.projectName) // 项目名称
      this.$set(this.model, 'finalNo', event.finalNo) // 项目编号
      this.$set(this.model, 'teamName', event.oldTeamId ? event.oldTeamId : event.teamName) // 经营团队
      this.$set(this.model, 'undertaker', event.undertaker) // 项目承接人
      this.$set(this.model, 'projectEstablishDate', event.projectEstablishDate) // 立项日期
      this.$set(this.model, 'signUnit', event.signUnit) // 签订单位
      this.$set(this.model, 'year', event.year) // 业绩归属年度
      this.$set(this.model, 'ownerUnit', event.ownerUnit) // 业主单位
      this.$set(this.model, 'contacts', event.contacts) // 联系人
      this.$set(this.model, 'contactTel', event.contactTel) // 联系方式
      this.$set(this.model, 'areaCode', event.areaCode) // 项目所在地址
      this.$set(this.model, 'projectAddress', event.projectAddress) // 项目所在详细地址
      this.$set(this.model, 'projectSource', event.projectSource) // 项目来源
      this.$set(this.model, 'estimatedContractAmount', event.estimatedContractAmount) // 预计合同额
      this.$set(this.model, 'estimatedContractcapitalChineseAmount', event.estimatedContractcapitalChineseAmount) // 预计合同额大写
      this.$set(this.model, 'establishReason', event.establishReason) // 立项事由及说明
      this.$set(this.model, 'attachment', event.attachment) // 项目附件
    },

    // 选择任务编号
    onTaskIdInput (item) {
      var event = item.choseObj[0]
      this.$set(this.model, 'categoryName', event.categoryName) // 业务分类
      this.$set(this.model, 'contractRate', event.contractRate) // 合同占比(%)
      this.$set(this.model, 'contractAmount', event.contractAmount) // 合同分配额(元)

      this.$set(this.model, 'productTeam', event.productTeam) // 生产团队
    },

    // 选择实施部门
    onExecuteDepartInput (item) {
      if (!item[0].minister) {
        this.$set(this.model, 'minister', undefined)
        return false
      }
      // 赋值部门负责人
      getAction('/api/erpmng/sys/api/queryUsersByUsernames', { usernames: item[0].minister }).then((res) => {
        var idsArr = []
        var ids = ''
        if (res && res.length) {
          res.map(value => {
            idsArr.push(value.empId)
          })
        }
        ids = idsArr.toString()
        this.$set(this.model, 'minister', ids)
        // this.$refs.form.resetFields('minister')
      })
    },
    add() {
      this.edit(this.modelDefault);
      this.userName = this.userInfo().empName;// 申请人名称
      this.$set(this.model, 'createBy', this.userInfo().empId) // 申请人
      this.$set(this.model, 'handlerDeptId', this.userInfo().deptId) // 申请人
      this.$set(this.model, 'createTime', moment().format('YYYY-MM-DD HH:mm')) // 申请人
      this.generatedFormNumber();
    },
    async edit(record) {
      // this.$refs.form.resetFields();
      this.model = await Object.assign({}, record);
      this.model1 = Object.assign({}, record)
      this.cust_lxr = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + record.ownerUnit + '\'';
      this.queryPaymentNodeListByMainId(this.model.id) // 获取款项进度列表
      this.queryTaskNodeListByMainId(this.model.id) // 获取任务进度列表
      // 获取项目数据
      if (this.model.projectId) {
        getAction(this.url.erpOmcProjectQueryById, { id: this.model.projectId }).then((res) => {
          if (res.success) {
            var event = res.result
            this.$set(this.model, 'finalNo', event.finalNo) // 项目编号
          }
        })
      }
      this.memberLoading = true
      getAction('/api/erp/omc/task/erpOmcTaskDistributionDt/list', { mainId: this.model.id })
        .then(response => {
          this.model.distributionDtList = response.result || []
        }).finally(() => {
          this.memberLoading = false
        })
      this.visible = true;
      this[this.customKey].forEach((val,index) => {
        val.width = this[this.customKey+'width'][index]
      })
      this[this.otherKey].forEach((val,index) => {
        val.width = this[this.otherKey+'width'][index]
      })
    },
    // 编辑获取款项进度列表
    queryPaymentNodeListByMainId (id) {
      if (!id) {
        return false
      }
      this.progressNodeVoLoading = true
      getAction('/api/erp/omc/task/erpOmcTaskDistribution/queryPaymentNodeListByMainId', { id }).then((res) => {
        if (res.success) {
          this.progressNodeVoList = res.result
        } else {
          this.queryPaymentListByProjectId(this.model.taskId)
        }
      }).finally(() => {
        this.progressNodeVoLoading = false
      })
    },
    // 获取开始的款项进度列表
    queryPaymentListByProjectId (taskId, flag) {
      getAction('/api/erp/omc/task/erpOmcTaskDistribution/queryTaskPaymentList', { taskId }).then((res) => {
        if (res.success) {
          this.progressNodeVoList = res.result
        }
      })
    },
    // 编辑获取任务进度列表
    queryTaskNodeListByMainId (id) {
      if (!id) {
        return false
      }
      this.templateLoading = true
      getAction('/api/erp/omc/task/erpOmcTaskDistribution/queryTaskNodeListByMainId', { id }).then((res) => {
        if (res.success) {
          this.templateDataList = res.result
        }
      }).finally(() => {
        this.templateLoading = false
      })
    },

    // 选择进度模板
    getTemplateList(data, obj) {
      if (data && data.length) {
        data.map(value => {
          value.id = this.getRandomNum()
        })
      }
      // 后端无良心，需要前端自己处理，当选择了“允许添加子节点”需要在每一个节点里面塞isAddChildNode值最后一个节点不用塞
      let isAddChildNode = obj.isAddChildNode;
      data.forEach((item, index) => {
        if (index === data.length - 1) {
          item.isAddChildNode = '0';
        } else {
          item.isAddChildNode = isAddChildNode;
        }
      });
      this.templateDataList = data;
    },
    // 获取唯一随机数
    getRandomNum() {
      let date = (new Date()).valueOf();// 获取时间戳
      let txt = '1234567890';// 生成的随机机器码
      let len = 19;// 机器码有多少位
      let pwd = '';// 定义空变量用来接收机器码
      for (let i = 0; i < len; i++) {
        pwd += txt.charAt(Math.floor(Math.random() * txt.length));// 循环机器码位数随机填充
      }
      return date + pwd
    },

    // 渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId };
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result);
          }
        });
      }
    },
    submitForm() {
      const that = this;

      // const total = this.model.distributionDtList.reduce((total, item) => {
      //   total += item.contractAmount
      //   return total
      // }, 0)
      // if (total !== this.model.contractAmount) {
      //   that.$message.warning('合同分配额总和必须等于任务委托合同额！');
      //   return
      // }

      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          let model = {};
          Object.assign(model, this.model)
          model.progressVoList = that.templateDataList || [] // 任务进度
          httpAction(httpurl, model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
              let params = { id: this.formData.dataId };
              getAction(this.url.queryById, params).then((res) => {
                if (res.success) {
                  this.model1 = res.result
                  // this.isSubmit = true
                }
              });
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            // this.model.estimatedContractAmount = estimatedContractAmount;
          })
        }
      })
    },

    // 点击打印
    onPrint () {
        let print = new Print({
          el: '#taskContent',
          popTitle: '任务委托详情 · 禾美环保',
          endCallback() {

          }
        })
      }

  }
}
</script>
<style lang="less" scoped>
.print_style{
  position: absolute;
  top: 0;
  z-index: -1111;
}
</style>
<style>
  @import "../../../../../utils/print.css";
</style>
